# -*- coding: utf-8 -*-

from muti import *
import matplotlib.pyplot as plt

state = State()
state.p_pos = np.random.random((state.p_n, 2)) * 2 - 1
# state.p_pos = np.array([
#     [-0.32927848, -0.39141907],
#     [-0.74393405, -0.37328075],
#     [-0.79778117,  0.08230744]
# ])
print(state.p_pos.tolist())

fig, ax = plt.subplots()
width = 5
ax.set_xlim(-width, width)
ax.set_ylim(-width, width)
ax.set_aspect(1)

angle = SolveState1(state, 2)

def DrawCircle(o, r, ls):
    t = np.linspace(0, np.pi*2, 100)
    x = r * np.cos(t)
    x[:] += o[0]
    y = r * np.sin(t)
    y[:] += o[1]
    plt.plot(x, y, ls)

plt.scatter([state.e_pos[0]], [state.e_pos[1]], c="r")
plt.scatter(state.p_pos[:, 0], state.p_pos[:, 1], c="b")

for i in range(state.p_n):
    o, r = ACircle(state.p_pos[i], state.e_pos, state.p_vmax[i] / state.e_vmax)
    DrawCircle(o, r, "b-")

pix = int(np.random.random() * state.p_n)
# pix = 2
print(pix)
print("*" * 30)
plt.scatter(state.p_pos[pix: pix+1, 0], state.p_pos[pix: pix+1, 1], c="g")
# angle = SolveState1(state, pix)
angle = SolveState2(state, pix)

vec = state.p_pos[pix] - state.e_pos
sina = np.sin(angle)
cosa = np.cos(angle)
x = cosa * vec[0] + sina * vec[1]
y = - sina * vec[0] + cosa * vec[1]
vec = np.array([x, y])

o, r = ACircle(state.e_pos + vec, state.e_pos, state.p_vmax[pix] / state.e_vmax)
DrawCircle(o, r, "r-")

plt.show()